home *** CD-ROM | disk | FTP | other *** search
/ Programming a Multiplayer FPS in DirectX / Programming a Multiplayer FPS in DirectX (Companion CD).iso / DirectX / dxsdk_oct2004.exe / dxsdk.exe / Utilities / MView / gxu / loadutil.h < prev    next >
Encoding:
C/C++ Source or Header  |  2004-09-30  |  4.4 KB  |  165 lines

  1. #pragma once
  2.  
  3. #ifndef __LOADUTIL_H
  4. #define __LOADUTIL_H
  5.  
  6. namespace GXU
  7. {
  8.  
  9. /*//////////////////////////////////////////////////////////////////////////////
  10. //
  11. // File: loadutil.h
  12. //
  13. // Copyright (C) 1999 Microsoft Corporation. All Rights Reserved.
  14. //
  15. //
  16. //////////////////////////////////////////////////////////////////////////////*/
  17.  
  18.  
  19. struct SLoadVertex
  20. {
  21.     D3DXVECTOR3    m_vPos;
  22.     D3DXCOLOR  m_color;
  23.     D3DXVECTOR2    m_uvTex1;
  24.     D3DXVECTOR3 m_vNormal;
  25.     DWORD       m_wPointRep;
  26.     DWORD       m_wPointList;
  27.     bool        m_bOwned;
  28.     WORD        m_iSmoothingGroup;
  29.     WORD        m_cSmoothingGroupFaces;
  30.     DWORD       m_iFVFDataOffset;
  31. };
  32.  
  33. struct SLoadedFace
  34. {
  35. public:
  36.     SLoadedFace()        
  37.         { InitEmpty(); }
  38.     SLoadedFace( DWORD w0, DWORD w1, DWORD w2 )
  39.     {
  40.         Init(w0, w1, w2);
  41.     }
  42.     SLoadedFace( DWORD wIndices[3] )
  43.     {
  44.         Init(wIndices[0], wIndices[1], wIndices[2]);
  45.     }
  46.  
  47.     void Init(DWORD w0, DWORD w1, DWORD w2)
  48.     {
  49.         m_bColorSpecified = false;
  50.         m_bMaterialSpecified = false;
  51.         m_bAttributeSpecified = false;
  52.         m_bSmoothingGroupSpecified = false;
  53.         m_wIndices[0] = w0;
  54.         m_wIndices[1] = w1;
  55.         m_wIndices[2] = w2;
  56.     }
  57.  
  58.     void InitEmpty()
  59.     {
  60.         Init(UNUSED32, UNUSED32, UNUSED32);
  61.     }
  62.  
  63.     DWORD m_wIndices[3];
  64.     WORD m_bColorSpecified:1;
  65.     WORD m_bMaterialSpecified:1;
  66.     WORD m_bAttributeSpecified:1;
  67.     WORD m_bSmoothingGroupSpecified:1;
  68.     D3DXCOLOR m_colorFace;
  69.     DWORD m_matid;
  70.     DWORD m_attr;
  71.     WORD m_iSmoothingGroup;
  72. };
  73.  
  74. struct SCorner
  75. {
  76.     DWORD        m_wPoint;
  77.     DWORD        m_wFace;
  78.     WORD        m_bNormalSpecified:1;
  79.     WORD        m_bUvSpecified:1;
  80.     D3DXVECTOR2    m_uvTex1;
  81.     D3DXVECTOR3   m_vNormal;
  82. };
  83.  
  84. // structure used to define additional data not in a SLoadVertex
  85. struct SFVFData
  86. {
  87.     DWORD dwFVF;
  88.     DWORD cBytesPerVertex;
  89.     DWORD *rgiFVFData;
  90.     DWORD iTexCoordOffset;  // 0 if no normal tex data present in x file, 1 if separate texcoord block of data specified
  91. };
  92.  
  93. HRESULT InitVertices(SLoadVertex *&rglvVertices, DWORD cVertices);
  94. HRESULT InitCorners(SCorner *&rgCorners, DWORD cCorners);
  95. HRESULT InitFaces(SLoadedFace *&rglfFaces, DWORD cFaces);
  96. bool BEqualWedges(SLoadVertex &lv1, SLoadVertex &lv2);
  97.  
  98. HRESULT SetVertexColor(SLoadedFace *pface, DWORD iPoint, D3DXCOLOR &color, SLoadVertex **prglvLoaded, DWORD *pcVertices, DWORD *pcVerticesMax);
  99. HRESULT SetVertexAttributes(SLoadedFace *pface, DWORD iPoint, D3DXVECTOR3 *pvNormal, D3DXVECTOR2 *puvTex1, SLoadVertex **prglvLoaded, DWORD *pcVertices, DWORD *pcVerticesMax);
  100. DWORD FindPoint(PDWORD pwIndices, DWORD iPointSearch, SLoadVertex *rglvVerts);
  101. HRESULT SetMesh(SLoadedFace *&rglfFaces, DWORD cFaces, 
  102.                 SLoadVertex *&rglvLoaded, DWORD cVertices, 
  103.                 SCorner *rgCorners, DWORD cCorners,
  104.                 SFVFData *pFVFData, BOOL bUsePointRepData, DWORD *rgdwAdjacencyFile,
  105.                 DWORD options, DWORD fvf, LPDIRECT3DDEVICE9 pD3D, 
  106.                 LPD3DXMESH *ppMesh, LPD3DXBUFFER *ppbufAdjacency);
  107.  
  108. HRESULT
  109. CreateMaterialBuffer(LPD3DXMATERIAL rgmat, DWORD cmat, LPD3DXBUFFER *ppbufMaterials);
  110.  
  111. HRESULT
  112. MergeMaterialBuffers(LPD3DXBUFFER pbufMat1, DWORD cmat1, LPD3DXBUFFER pbufMat2, DWORD cmat2, LPD3DXBUFFER *ppbufMaterials);
  113.  
  114. const int x_cbBufferSize = 256;
  115.  
  116. class CFileContext
  117. {
  118. public:
  119.     CFileContext(IStream *pstream)
  120.         :m_pstream(pstream), m_ichBuffer(0), m_cchBuffer(0), m_bEndOfFile(false) {}
  121.  
  122.     HRESULT GetLine(char *szBuffer, int cchBuffer, bool &bEOF);
  123.  
  124.     HRESULT Rewind()
  125.     {
  126.         m_bEndOfFile = false;
  127.  
  128.         LARGE_INTEGER li;
  129.         li.QuadPart = 0;
  130.         return m_pstream->Seek(li, STREAM_SEEK_SET, NULL);
  131.     }
  132. private:
  133.  
  134.     inline HRESULT GetChar(char *szBuffer, bool &bEOF)
  135.     {
  136.         bEOF = false;
  137.  
  138.         if (m_ichBuffer < m_cchBuffer)
  139.         {
  140.             *szBuffer = m_szBuffer[m_ichBuffer];
  141.             m_ichBuffer += 1;
  142.             return S_OK;
  143.         }
  144.         else
  145.         {
  146.             return GetCharHelper(szBuffer, bEOF);
  147.         }
  148.  
  149.     }
  150.  
  151.     HRESULT GetCharHelper(char *szBuffer, bool &bEOF);
  152.  
  153.     IStream *m_pstream;
  154.     char m_szBuffer[x_cbBufferSize];
  155.  
  156.     ULONG m_ichBuffer;
  157.     ULONG m_cchBuffer;
  158.     bool m_bEndOfFile;
  159. };
  160.  
  161. }
  162.  
  163. #endif  // #ifndef __LOADUTIL_H
  164.  
  165.